package com.whfc.wxmp.api.fim.controller;

import com.whfc.common.result.Result;
import com.whfc.common.result.ResultUtil;
import com.whfc.common.util.JSONUtil;
import com.whfc.wxmp.annotation.CurrentWxUser;
import com.whfc.fuum.entity.WxUser;
import com.whfc.entity.param.warn.AppWarnHandleParam;
import com.whfc.fim.dto.FimResultDTO;
import com.whfc.wxmp.api.fim.service.WxFimWarnService;
import com.whfc.wxmp.util.RequestConetxtUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;


/**
 * @Description: 智能监控报警
 * @author: xugcheng
 * @version: 1.0
 * @date: 2019/11/30 8:49
 */
@RestController
@RequestMapping("mp/api")
public class WxFimWarnController {

    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private WxFimWarnService wxFimWarnService;


    /**
     * 查询智能监控报警消息详情
     *
     * @param loginUser
     * @param warnId
     * @return
     */
    @GetMapping(value = {"fim/warn/detail", "msg/warn/fim/detail"})
    public Result getFimWarnMsgDetail(@CurrentWxUser WxUser loginUser,
                                      @RequestParam("warnId") Integer warnId) {
        logger.info("WXMPUA|{}|{}|{}|{}|{}",
                loginUser.getId(), RequestConetxtUtil.getAppType(), RequestConetxtUtil.getPage(),
                "查询智能监控报警消息详情", RequestConetxtUtil.getParameters());
        FimResultDTO warnDetail = wxFimWarnService.getFimWarnDetail(warnId);
        return ResultUtil.success(warnDetail);
    }

    /**
     * 处理智能监控报警消息
     *
     * @param loginUser
     * @param body
     * @return
     */
    @PostMapping(value = {"fim/warn/handle", "msg/warn/fim/handle"})
    public Result handleFimWarn(@CurrentWxUser WxUser loginUser,
                                @RequestBody @Validated AppWarnHandleParam body) {
        logger.info("WXMPUA|{}|{}|{}|{}|{}",
                loginUser.getId(), RequestConetxtUtil.getAppType(), RequestConetxtUtil.getPage(),
                "处理智能监控报警消息", JSONUtil.toString(body));
        wxFimWarnService.handleFimWarn(loginUser, body);
        return ResultUtil.success();
    }


}
